<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>poi上传</title>
        <link rel="stylesheet" type="text/css" href="/webapp/css/easyui.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/icon.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/color.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/public.css">
        <script type="text/javascript" src="/webapp/js/lib/jquery.min.js"></script>
        <script type="text/javascript" src="/webapp/js/lib/jquery.easyui.min.js"></script>
        <script type="text/javascript" src="/webapp/js/lib/jquery.global.settings.js"></script>
        <script type="text/javascript" src="/webapp/js/lib/ajaxfileupload.js"></script>
        <script type="text/javascript" src="/webapp/js/common/config.js"></script>
    </head>
    <body>
        <div class="easyui-container-fluid">
            <div class="easyui-panel" style="border: none;">
                <div id="nav" class="nav">
                </div>
                <div class="easyui-panel" style="width:100%;border:none;">
                    <form id="ff">
                        <div style="margin-bottom:20px;">
                            <label class="item-label">确认状态：</label>
                            <select name="confirmStatus" class="easyui-combobox" data-options="panelHeight:'auto'" style="width:100px;">
                                <option value="0">未确认</option>
                                <option value="1" >已确认</option>
                                <option value="-1" >无</option>
                                <option value="">--全部--</option>
                            </select>
                            <label class="item-label">启用状态：</label>
                            <input id="entityStatus" class="easyui-switchbutton" checked style="width:80px;height:30px;" onText="启用" offText="禁用"  >
                            <label class="item-label">店铺名称：</label>
                            <input type="text" name="shopName"  class="easyui-textbox" style="width:100px;"/>
                            <label class="item-label">店铺地址：</label>
                            <input type="text" name="address"  class="easyui-textbox" style="width:100px;"/>
                            <label class="item-label">片区编码：</label>
                            <input type="text" name="areaCode"  class="easyui-textbox" style="width:100px;"/>
                            <label class="item-label">样本编码：</label>
                            <input type="text" name="sampleCode"  class="easyui-textbox" style="width:100px;"/>
                            <a href="javascript:void(0);" class="easyui-linkbutton c8" style="margin-left:40px;width:80px;" onclick="searchBy()">查询</a>
                        </div>
                    </form>
                </div>
                <div class="table-wrapper">
                    <table id="datagrid" data-options="fitColumns:true,scrollbarSize:0">
                        <thead>
                            <tr>
                                <th data-options="field:'shopName',align:'center'" width="80">店铺名称</th>
                                <th data-options="field:'address',align:'center'" width="130">店铺地址</th>
                                <th data-options="field:'channelInfo',align:'center'" width="70">渠道信息</th>
                                <th data-options="field:'lonAndLat',align:'center'" width="80">经纬度</th>
                                <th data-options="field:'areaCode',align:'center'" width="50">片区编码</th>
                                <th data-options="field:'sampleCode',align:'center'" width="50">样本编码</th>
                                <th data-options="field:'trueShopName',align:'center'" width="80">店铺名称(真实)</th>
                                <th data-options="field:'trueLonAndLat',align:'center'" width="80">经纬度(真实)</th>
                                <th data-options="field:'createTime',align:'center'" width="80">创建时间</th>
                                <th data-options="field:'confirmStatus',align:'center',formatter:confirmStatusFormatter" width="50">确认状态</th>
                                <th data-options="field:'entityStatus',align:'center',formatter:entityStatusFormatter" width="30">状态</th>
                                <th data-options="field:'action',align:'center',formatter:actions" width="80">操作</th>
                            </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>

        <div id="confirmShop" class="easyui-dialog"  style="padding:5px;width:1100px;height:770px;"
             title="店铺确认" iconCls="icon-ok"
             toolbar="#dlg-toolbar" buttons="#dlg-buttons" closed="true">
            <div class="easyui-container-fluid">
                <input id="dataId" style="display: none" />
                <div style="margin-bottom:10px;">
                    <label class="item-label">店铺名称：</label>
                    <input type="text" class="easyui-textbox" name="shopName" id="shopNameEdit" style="margin-left:40px;width:300px;" data-options="required:true"/>
                    <a href="javascript:void(0);" class="easyui-linkbutton c8" style="margin-left:40px;width:80px;" onclick="searchPoi1()">查询</a>
                    <label class="item-label">查找范围：</label>
                    <input type="text" class="easyui-textbox" name="radius" id="radiusEdit" data-options="required:true"/>
                    <label class="item-label">片区码：</label>
                    <input type="text" class="easyui-textbox" name="areaCode" id="areaCodeEdit"/>
                    <label class="item-label">访问ip：</label>
                    <select id="ip" class="easyui-combobox" data-options="panelHeight:'auto'" style="width:100px;float:right">
                        <option value="119.61.37.98" >外网ip</option>
                        <option value="192.168.0.190">内网ip</option>
                    </select>
                    <a href="javascript:void(0);" class="easyui-linkbutton c6" style="margin-left:40px;width:80px;" onclick="pass()">PASS</a>
                </div>
                <div style="margin-bottom:10px;">
                    <label class="item-label">店铺地址：</label>
                    <input type="text" class="easyui-textbox" name="adress" id="addressEdit" style="margin-left:40px;width:300px;" data-options="required:true"/>
                    <a href="javascript:void(0);" class="easyui-linkbutton c8" style="margin-left:40px;width:80px;" onclick="searchPoi2()">查询</a>
                    <label class="item-label">渠道信息：</label>
                    <input type="text" class="easyui-textbox" name="channelInfo" id="channelInfoEdit"/>
                    <label class="item-label">经纬度：</label>
                    <input type="text" class="easyui-textbox" name="lonAndLat" id="lonAndLatEdit"/>
                    <label class="item-label">样本码：</label>
                    <input type="text" class="easyui-textbox" name="sampleCode" id="sampleCodeEdit"/>
                </div>

                <div class="table-wrapper">
                    <table id="datagridTx" data-options="fitColumns:true,scrollbarSize:0">
                        <thead>
                            <tr>
                                <th data-options="field:'name',align:'center'" width="80">(腾讯)店铺名称</th>
                                <th data-options="field:'address',align:'center'" width="130">店铺地址</th>
                                <th data-options="field:'type',align:'center'" width="100">店铺类型</th>
                                <th data-options="field:'location',align:'center'" width="80">经纬度</th>
                                <th data-options="field:'city',align:'center',formatter:cityFormatter" width="80">城市</th>
                                <th data-options="field:'distance',align:'center'" width="80">距中心点</th>
                                <th data-options="field:'Similarity',align:'center',formatter:similarFormatter" width="50">相似度</th>
                                <th data-options="field:'action',align:'center',formatter:actionsFormatter" width="50">操作</th>
                            </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                    <table id="datagridGaode" data-options="fitColumns:true,scrollbarSize:0">
                        <thead>
                            <tr>
                                <th data-options="field:'name',align:'center'" width="80">(高德)店铺名称</th>
                                <th data-options="field:'address',align:'center'" width="130">店铺地址</th>
                                <th data-options="field:'type',align:'center'" width="100">店铺类型</th>
                                <th data-options="field:'location',align:'center'" width="80">经纬度</th>
                                <th data-options="field:'city',align:'center',formatter:cityFormatter" width="80">城市</th>
                                <th data-options="field:'distance',align:'center'" width="80">距中心点</th>
                                <th data-options="field:'Similarity',align:'center',formatter:similarFormatter" width="50">相似度</th>
                                <th data-options="field:'action',align:'center',formatter:actionsFormatter" width="50">操作</th>
                            </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </body>
    <script type="text/javascript">
        var code = getQueryParameter("code");
        $(function () {
            setNav();
            var height = $(window).height();
            var nav_height = $("#nav")._outerHeight();
            var ff_height = $("#ff").height();
            var table_height = height-nav_height-ff_height-40;
            $("#datagrid").css("max-height",table_height);
            $("#datagrid").datagrid({
                pagination:true,
                rownumbers:true,
                checkOnSelect:false,
                onBeforeSelect:function (index,row) {
                    return false;
                }
            }).datagrid("getPager").pagination({
                onSelectPage:searchBy
            });
            $("#datagridTx").css("max-height",400);
            $("#datagridTx").datagrid({
                rownumbers:true,
                checkOnSelect:false,
                onBeforeSelect:function (index,row) {
                    return false;
                }
            }).datagrid("getPager");
            $("#datagridGaode").css("max-height",240);
            $("#datagridGaode").datagrid({
                rownumbers:true,
                checkOnSelect:false,
                onBeforeSelect:function (index,row) {
                    return false;
                }
            }).datagrid("getPager");

            searchBy();
        });

        function searchBy(page,size) {
            var data = getFormData(document.getElementById("ff"));
            data.uploadRecordCode = code;
            data.entityStatus = $("#entityStatus").switchbutton("options").checked==true?"OK":"DISABLE";
            var pager = {page:page,size:size};
            if(!size){
                pager['page']= 1;
                pager['size'] = $("#datagrid").datagrid("getPager").pagination("options").pageSize||100;
            }
            $.ajax({
                url:config.url + "/shop/getFileData?"+transfer2url(pager),
                type:"get",
                dataType: "json",
                data: data,
                xhrFields:{withCredentials:true},
                beforeSend:function () {
                    $.messager.progress({
                        title:"请稍等",
                        interval:50,
                        text:"数据加载中..."
                    });
                },
                complete:function () {
                    $.messager.progress("close");
                },
                success:function(data){
                    $("#datagrid").datagrid("loadData", data.msg);
                    $.messager.progress("close");
                },
                error:function(data){
                    $.messager.progress("close");
                }
            });


        }

        function confirmStatusFormatter(val,row) {
            if (row.confirmStatus==0) {
                return "<span style='color: #aea812'>未确认</span>";
            }else if (row.confirmStatus==1) {
                return "<span style='color: #4cae4c'>已确认</span>";
            }else if (row.confirmStatus==-1) {
                return "<span style='color: #ae1a1f'>无</span>";
            }
            return "--";
        }
        
        function entityStatusFormatter(val,row) {
            if(val=="DISABLE"){
                return "<a class='l-btn-left l-btn-icon-left' style='width:24px;height:24px;'><span class='l-btn-icon icon-no'></span></a>";
            }else{
                return "<a class='l-btn-left l-btn-icon-left' style='width:24px;height:24px;'><span class='l-btn-icon icon-ok'></span></a>";
            }
        }

        function actions(val, row){
            var rowJson = JSON.stringify(row);
            var disableBtnText = row.entityStatus=='OK'?'禁用':"启用";
            return "<a href='javascript:void(0);' class='easyui-linkbutton l-btn l-btn-small' "+
                "style='width:60px;' onclick='edit("+rowJson+")'>查找</a>&nbsp;&nbsp;"+
                "<a href='javascript:void(0);' class='easyui-linkbutton l-btn l-btn-small' style='width:60px;' onclick='updateStatus(\""+row.id+"\")'>"+disableBtnText+"</a>";
        }

        function updateStatus(id) {
            $.messager.confirm("提示","您确定禁用/启用吗？",function (f) {
                if(f){
                    $.ajax({
                        url:config.url+"/shop/disableOrEnable/"+id,
                        type:"DELETE",
                        dataType:"json",
                        xhrFields:{withCredentials:true},
                        beforeSend:function () {
                            $.messager.progress({
                                title:"请稍等",
                                interval:50,
                                text:"操作进行中..."
                            });
                        },
                        complete:function () {
                            $.messager.progress("close");
                        },
                        success:function (data) {
                            if (data.code == 200) {
                                $.messager.alert("提示","操作成功","info",function () {
                                    searchBy();
                                });
                            }else {
                                $.messager.alert("提示", data.msg, "error");
                            }
                        },
                        error:function (data) {

                        }
                    });
                }
            });
        }

        function edit(row) {
            //清空数据
            $("#dataId").val("");
            $("#shopNameEdit").textbox("setValue", "");
            $("#addressEdit").textbox("setValue", "");
            $("#radiusEdit").textbox("setValue", "");
            $("#channelInfoEdit").textbox("setValue", "");
            $("#lonAndLatEdit").textbox("setValue", "");
            $("#areaCodeEdit").textbox("setValue", "");
            $("#sampleCodeEdit").textbox("setValue", "");

            //填充数据
            $("#dataId").val(row.id);
            $("#shopNameEdit").textbox("setValue", row.shopName);
            $("#addressEdit").textbox("setValue", row.address);
            $("#radiusEdit").textbox("setValue", row.radius);
            $("#channelInfoEdit").textbox("setValue", row.channelInfo);
            $("#lonAndLatEdit").textbox("setValue", row.lonAndLat);
            $("#areaCodeEdit").textbox("setValue", row.areaCode);
            $("#sampleCodeEdit").textbox("setValue", row.sampleCode);
            $("#sampleCodeEdit").textbox('readonly', true);
            $("#areaCodeEdit").textbox('readonly', true);
            $("#channelInfoEdit").textbox('readonly', true);
            $("#lonAndLatEdit").textbox('readonly', true);

            searchPoi1();
            //显示弹窗
            $('#confirmShop').dialog({
                width:"1350px",
                left:'100px'
            }).dialog('open');
        }

        function searchPoi1() {
            let shopName = $("#shopNameEdit").textbox("getValue");
            poi(shopName);
        }
        function searchPoi2() {
            let address = $("#addressEdit").textbox("getValue");
            poi(address);
        }

        function poi(keyword) {
            var data = {};
            data.radius = $("#radiusEdit").textbox("getValue");
            data.longlat = $("#lonAndLatEdit").textbox("getValue");
            data.keyword = keyword;
            data.token = "Z6z1hy!lVm";
            var url = "http://" + $("#ip").textbox("getValue") + ":8000/feb/map/select";
            $.ajax({
                url:url,
                type:"post",
                dataType: "json",
                data: data,
                beforeSend:function () {
                    $.messager.progress({
                        title:"请稍等",
                        interval:30,
                        text:"数据加载中..."
                    });
                },
                complete:function () {
                    $.messager.progress("close");
                },
                success:function(data){
                    $.messager.progress("close");
                    if (data.code == 200) {
                        var gaodeData = {};
                        gaodeData.content = data.msg.gaode.data;
                        var tengxunData = {};
                        tengxunData.content = data.msg.tengxun.data;
                        $("#datagridGaode").datagrid("loadData", gaodeData);
                        $("#datagridTx").datagrid("loadData", tengxunData);

                    }else{
                        $.messager.alert("提示", data.msg, "info");
                    }
                },
                error:function(data){
                    $.messager.progress("close");
                }
            });
        }

        function cityFormatter(val,row) {
            return row.adname + "(" + row.cityname + ")";
        }
        function similarFormatter(val,row) {
            if (val) {
                var num = val * 100;
                return num.toFixed(2) + "%";
            }
            return "0";
        }

        function actionsFormatter(val,row) {
            var rowJson = JSON.stringify(row);
            rowJson = rowJson.replace(/'/g,"’");
            return "<a href='javascript:void(0);' class='easyui-linkbutton l-btn l-btn-small' "+
                "style='width:60px;' onclick='confirm("+rowJson+")'>确认</a>";
        }

        function confirm(row) {
            var data = {};
            data.id = $("#dataId").val();
            data.trueShopName = row.name;
            data.trueAddress = row.address;
            data.trueLonAndLat = row.location;
            data.infoSources = row.infoSources;
            data.city = cityFormatter(row.city, row);
            data.type = row.type;
            data.distance = row.distance;

            // $.messager.confirm("提示", "您确定选择此数据吗？", function (flag) {
            //     if (flag) {
                    $.ajax({
                        url: config.url + "/shop/confirmShop",
                        type: "post",
                        data:data,
                        xhrFields: {withCredentials: true},
                        dataType:'json',
                        beforeSend: function () {
                            $.messager.progress({
                                title: "请稍等",
                                interval: 30,
                                text: "数据加载中..."
                            });
                        },
                        success: function (data) {
                            $.messager.progress("close");
                            if (data.code == 200) {
                                $('#confirmShop').dialog('close');
                                $.messager.show({
                                    title: '提示',
                                    msg: "操作成功",
                                    timeout: 500,
                                    showType: 'fade'
                                });
                                searchBy();
                                confirm_continuous();
                            }else{
                                $.messager.alert("提示", data.msg, "info");
                            }
                        }
                    })
            //     }
            // })
        }

        function pass() {
            var id = $("#dataId").val();
            $.ajax({
                url: config.url + "/shop/pass/"+id,
                type: "delete",
                xhrFields: {withCredentials: true},
                dataType:'json',
                // beforeSend: function () {
                //     $.messager.progress({
                //         title: "请稍等",
                //         interval: 30,
                //         text: "数据加载中..."
                //     });
                // },
                success: function (data) {
                    // $.messager.progress("close");
                    if (data.code == 200) {
                        $('#confirmShop').dialog('close');
                        $.messager.show({
                            title: '提示',
                            msg: "操作成功",
                            timeout: 500,
                            showType: 'fade'
                        });
                        searchBy();
                        confirm_continuous();
                    }else{
                        $.messager.alert("提示", data.msg, "info");
                    }
                }
            })
        }
        
        function confirm_continuous() {
            $.ajax({
                url: config.url + "/shop/getOne/",
                type: "get",
                data:{uploadRecordCode: code},
                xhrFields: {withCredentials: true},
                dataType:'json',
                success: function (data) {
                    if (data.code == 200) {
                        if (data.msg) {
                            edit(data.msg);
                        }else {
                            $.messager.alert("提示", "当前文件已处理完毕", "info");
                        }
                    }else{
                        $.messager.alert("提示", data.msg, "info");
                    }
                }
            })
        }
    </script>
</html>